from typing import TYPE_CHECKING

from sqlalchemy import Boolean, Column, Integer, String, ForeignKey
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import Mapped

from app.db.base_class import Base
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
class User(Base):

    mobile = Column(String(64), default="", comment="手机号")
    hashed_password = Column(String(256), default="", nullable=False)
    is_active = Column(Boolean(), default=True, comment="是否激活")
    active_key = Column(String(128), default="", comment="激活码")
    is_superuser = Column(Boolean(), default=False, comment="是否管理员")

    role = Column(String(128), default="", comment="用户角色")
    user_type = Column(String(128), default="", comment="用户类型")

    def verify_password(self,plain_password, hashed_password):
        return pwd_context.verify(plain_password, hashed_password)
    def get_password_hash(self,password):
        return pwd_context.hash(password)

    __table_args__ = ({'comment': '用户'})
class Account(Base):

    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"), index=True)
    data_dir = Column(String(128), default="", comment="数据保存目录")
    mobile = Column(String(128), default="", comment="账号号码")
    mac = Column(String(128), default="", comment="物理地址")
    ip = Column(String(128), default="", comment="IP地址")

    __table_args__ = ({'comment': '小红书账号'})

class UserRAccount(Base):

    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"), index=True)
    account_id: Mapped[int] = mapped_column(ForeignKey("account.id"), index=True)
    __table_args__ = ({'comment': '用户小红书权限'})
